//
//  AppGlobal.m
//  Keping
//
//  Created by 23 on 2017/12/7.
//  Copyright © 2017年 柯平. All rights reserved.
//

#import "AppGlobal.h"
#import <AVFoundation/AVFoundation.h>
#import <AssetsLibrary/AssetsLibrary.h>

@implementation AppGlobal

#pragma mark - 权限判断
//////////////////////////////////用户模块//////////////////////////////////



/**判断是否有相机权限*/
+ (BOOL)isCameraDeviceAvalable
{
    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    if (authStatus == AVAuthorizationStatusDenied || authStatus == AVAuthorizationStatusRestricted) {
        
        UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"无法使用相机" message:@"请在iPhone的\"设置-隐私-相机\"中允许访问相机" preferredStyle:UIAlertControllerStyleAlert];
        [alertVc addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
        
        
        [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertVc animated:YES completion:nil];
        
        
        return NO;
    }
    
    
    return YES;
}

/**判断是否有相册访问权限*/
+ (BOOL)isAssetsLibraryAvalable
{
    ALAuthorizationStatus authStatus = [ALAssetsLibrary authorizationStatus];
    if (authStatus == ALAuthorizationStatusDenied || authStatus == ALAuthorizationStatusRestricted) {
        UIAlertView *alertview = [[UIAlertView alloc]initWithTitle:@"无法使用相册" message:@"请在iPhone的\"设置-隐私-相册\"中允许访问相册" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alertview show];
        
        return NO;
    }
    
    return YES;
}


@end
